package com.youths.controller;

import com.youths.response.Result;
import com.youths.service.ConsumerInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/")
@Slf4j
@RestController
public class ConsumerInfoController {

    @Autowired
    ConsumerInfoService consumerInfoService;

    @GetMapping("/back/getConsumerInfoList")
    @ResponseBody
    public Result getConsumerInfoList(@RequestParam("pageNum") Integer pageNum,
                                      @RequestParam("id") Integer id,
                                      @RequestParam("type") Integer type,
                                      @RequestParam("name") String name,
                                      @RequestParam("account") String account){
        return Result.success(consumerInfoService.getConsumerInfoList(pageNum,id,type,name,account));
    }

    @GetMapping("/back/getAdminInfoList")
    @ResponseBody
    public Result getAdminInfoList(@RequestParam("pageNum") Integer pageNum,
                                   @RequestParam("type") Integer type,
                                   @RequestParam("name") String name,
                                   @RequestParam("account") String account){
        return Result.success(consumerInfoService.getAdminInfoList(pageNum,type,name,account));
    }

    @PostMapping("/back/resetAdminPassword")
    @ResponseBody
    public Result resetAdminPassword(@RequestParam("adminId") Integer adminId){
        return Result.success(consumerInfoService.resetAdminPassword(adminId));
    }

    @PostMapping("/back/updatePower")
    @ResponseBody
    public Result updatePower(@RequestParam("adminId") Integer adminId,
                              @RequestParam("type") Integer type){
        return Result.success(consumerInfoService.updatePower(adminId,type));
    }

    @PostMapping("/back/updateState")
    @ResponseBody
    public Result updateState(@RequestParam("adminId") Integer adminId,
                              @RequestParam("type") Integer type){
        return Result.success(consumerInfoService.updateState(adminId,type));
    }

    @PostMapping("/back/resetConsumerPassword")
    @ResponseBody
    public Result resetConsumerPassword(@RequestParam("consumerId") Integer consumerId){
        return Result.success(consumerInfoService.resetConsumerPassword(consumerId));
    }

    @PostMapping("/back/changeAdminPassword")
    @ResponseBody
    public Result changeAdminPassword(@RequestParam("account") String account,
                                      @RequestParam("password") String password,
                                      @RequestParam("newPass") String newPass){
        return Result.success(consumerInfoService.changeAdminPassword(account,password,newPass));
    }

    @PostMapping("/back/createExpert")
    public Result createExpert(@RequestParam("account") String account,
                               @RequestParam("name") String name,
                               @RequestParam("company") String company,
                               @RequestParam("title") String title){
        return Result.success(consumerInfoService.createExpert(account,name,company,title));
    }

}
